﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DBLClient.DBLUserPersonService;
namespace DBLClient.DBLForm
{
    public partial class EditUserPersonForm : Form
    {
        private int usermemberid;
        private string dblno = string.Empty;
         public EditUserPersonForm(int usermemberid, string dblno)
        {
            InitializeComponent();
            this.usermemberid = usermemberid;
            this.dblno = dblno;

            FillUserPersonInfo();
        }
         private void FillUserPersonInfo()
         {
             UserPersonService user = new UserPersonService();
             DataSet ds = user.FindPersonDetailByID(this.usermemberid.ToString());
             if (ds.Tables[0].Rows.Count != 0)
             {
                 textBoxFullName.Text = ds.Tables[0].Rows[0]["fullname"].ToString();
                 textBoxAddress.Text = ds.Tables[0].Rows[0]["address"].ToString();
                 textBoxDescription.Text = ds.Tables[0].Rows[0]["description"].ToString();

                 textBoxNickName.Text = ds.Tables[0].Rows[0]["nickname"].ToString();
                 textBoxKeyword1.Text = ds.Tables[0].Rows[0]["keyword1"].ToString();
                 textBoxKeyword2.Text = ds.Tables[0].Rows[0]["keyword2"].ToString();
                 textBoxKeyword3.Text = ds.Tables[0].Rows[0]["keyword3"].ToString();
                 textBoxQQ.Text = ds.Tables[0].Rows[0]["nickname"].ToString();
                 textBoxPhone.Text = ds.Tables[0].Rows[0]["phone"].ToString();
                 textBoxMSN.Text = ds.Tables[0].Rows[0]["msn"].ToString();
                 textBoxWeibo.Text = ds.Tables[0].Rows[0]["weibo"].ToString();
                 textBoxWebsite.Text = ds.Tables[0].Rows[0]["website"].ToString();
                 textBoxMobilePhone.Text = ds.Tables[0].Rows[0]["mobilephone"].ToString();
                 textBoxFax.Text = ds.Tables[0].Rows[0]["fax"].ToString();
                 textBoxBlog.Text = ds.Tables[0].Rows[0]["blog"].ToString();
                 textBoxEmail.Text = ds.Tables[0].Rows[0]["email"].ToString();
                 textBoxDBLNo.Text = ds.Tables[0].Rows[0]["dblno"].ToString();
                 textBoxShenfenzheng.Text = ds.Tables[0].Rows[0]["shenfenzheng"].ToString();
             }
         }

         private void buttonUpdate_Click(object sender, EventArgs e)
         {
             //基本信息
             string fullname = textBoxFullName.Text;
             string address = textBoxAddress.Text;
             string description = textBoxDescription.Text;
             string shenfenzheng = textBoxShenfenzheng.Text;

             //搜索信息
             string nickname = textBoxNickName.Text;
             string keyword1 = textBoxKeyword1.Text;
             string keyword2 = textBoxKeyword2.Text;
             string keyword3 = textBoxKeyword3.Text;

             //联系信息
             string qq = textBoxQQ.Text;
             string phone = textBoxPhone.Text;
             string msn = textBoxMSN.Text;
             string weibo = textBoxWeibo.Text;
             string website = textBoxWebsite.Text;
             string mobilephone = textBoxMobilePhone.Text;
             string fax = textBoxFax.Text;
             string blog = textBoxBlog.Text;
             string email = textBoxEmail.Text;

             UserPersonService user = new UserPersonService();
             int affectnum = user.AddUpdateUserPerson(usermemberid, dblno, nickname, fullname, keyword1, keyword2, keyword3,
                 shenfenzheng, address, description, phone, fax, email, mobilephone, qq, msn, blog, weibo, website);

             if (affectnum == 1)
             {
                 MessageBox.Show("修改个人用户信息成功");
             }
             else
             {
                 MessageBox.Show("修改个人用户信息失败");
             }
         }

    }
}
